package com.rg.servlet;
//轮播图获取时servlet请求
import com.rg.model.GoodsModel;
import com.rg.service.GoodsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/GoodsRecommendServlet")
public class GoodsRecommendServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
        GoodsService goodsService=new GoodsService();
        //获取首页轮播图区域的商品
        List<GoodsModel>goodsScrolllist=goodsService.selectScrollGoods();
        //把拿到的轮播图商品存放在request中
        req.setAttribute("scrollGoods",goodsScrolllist);
        //获取首页推荐商品
        List<GoodsModel> IndexGoodsList=goodsService.selectIndexRecommendGoods();
        //把拿到的页面推荐商品存放在request中
        req.setAttribute("IndexGoodsList",IndexGoodsList);
        req.getRequestDispatcher("index.jsp").forward(req,resp);
    }
}
